define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'Company/index' + location.search,
                    add_url: 'Company/add',
                    edit_url: 'Company/edit',
                    del_url: 'Company/del',
                    multi_url: 'Company/multi',
                    import_url: 'Company/import',
                    table: 'address_location',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        /*{field: 'uid', title: __('Uid')},
                        {field: 'type', title: __('Type'), searchList: {"admin":__('Type admin'),"manage":__('Type manage'),"company":__('Type company'),"operatecenter":__('Type operatecenter')}, formatter: Table.api.formatter.normal},
                        {field: 'province', title: __('Province'), operate: 'LIKE'},
                        {field: 'city', title: __('City'), operate: 'LIKE'},
                        {field: 'county', title: __('County'), operate: 'LIKE'},
                        {field: 'detail', title: __('Detail'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'source', title: __('Source')},
                        {field: 'yz_id', title: __('Yz_id')},
                        {field: 'province_id', title: __('Province_id')},
                        {field: 'city_id', title: __('City_id')},
                        {field: 'region_id', title: __('Region_id')},
                        {field: 'town_id', title: __('Town_id')},
                        {field: 'subdstrict_id', title: __('Subdstrict_id')},
                        {field: 'oid', title: __('Oid')},
                        {field: 'free', title: __('Free')},
                        {field: 'adminid', title: __('Adminid')},*/
                        {field: 'admin.username', title: '用户名', operate: 'LIKE'},
                        {field: 'admin.nickname', title: '名称', operate: 'LIKE'},
                        {field: 'admin.mobile', title: __('Admin.mobile'), operate: 'LIKE'},
                        {field: 'admin.logintime', title: __('Admin.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'admin.loginip', title: __('Admin.loginip'), operate: 'LIKE'},
                        {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
